/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: UserServiceImpl
 * Author:   zmjha
 * Date:     2020/8/3 20:40
 * Description: 实现类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zmj.service.impl;

import com.zmj.entity.User;
import com.zmj.mapper.UserMapper;
import com.zmj.service.MailService;
import com.zmj.service.UserService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 〈一句话功能简述〉<br> 
 * 〈实现类〉
 *
 * @author zmjha
 * @create 2020/8/3
 * @since 1.0.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Resource
    private MailService mailService;


    @Override
    public void register(User user) {
        userMapper.insert(user);
        //获取激活码
        String code = user.getCode();
        System.out.println("code:"+code);
        //主题
        String subject = "登陆码";
        //激活码是我们点击邮件链接之后根据激活码查询用户，如果存在说明一致，将用户状态修改为“1”激活,有用户来访问服务器
        //上面的激活码发送到用户注册邮箱
        String context = "<a href='http://192.168.2.42:8080/checkCode?code="+code+"'>激活请点击:"+code+"进行激活您的账号</a>";
        //发送激活邮件
        mailService.sendHtmlMail(user.getEmail(),subject,context);
    }

    @Override
    public User checkCode(String code) {
        return userMapper.checkCode(code);
    }

    @Override
    public void updateUserStatus(User user) {
        userMapper.updateUserStatus(user);
    }

    @Override
    public User login(User user) {
        return userMapper.login(user);
    }
}